#!/data/data/com.termux/files/usr/bin/bash
sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main stable main@' $PREFIX/etc/apt/sources.list
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -o Dpkg::Options::="--force-confdef" full-upgrade -yq
apt install git nodejs-lts wget termux-services -yq
git clone https://gitee.com/miaomiaomiao86/SillyTavern.git -b staging 
cd SillyTavern
npm config set registry https://registry.npmmirror.com
export NODE_ENV=production
npm i --no-audit --no-fund --loglevel=error --no-progress --omit=dev
cd ~
mkdir -p $PREFIX/var/service/jiuguan
cd $PREFIX/var/service/jiuguan
wget https://gitee.com/miaomiaomiao86/Jiuguanjiaoben/raw/main/jiuguan.sh
chmod 755 jiuguan.sh
mv jiuguan.sh run
mkdir -p $PREFIX/var/service/jiuguan/log
cd $PREFIX/var/service/jiuguan/log
wget https://gitee.com/miaomiaomiao86/Jiuguanjiaoben/raw/main/log.sh
chmod 755 log.sh
mv log.sh run
cd ~/SillyTavern
node server.js